/**
 ***********************************************************************************************************************
 * Copyright (c) 2020, China Mobile Communications Group Co.,Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 *
 * @file        opencc_ISO8859.c
 *
 * @brief       Other character coding types converte to ISO-8859-1 coding or 
 *              ISO-8859-1 encoding converts to other character coding types.
 *
 * @revision
 * Date         Author          Notes
 * 2020-11-20   OneOS Team      First Version
 ***********************************************************************************************************************
 */

/**
1.单字节编码，最多能表示的字符范围是0-255，应用于英文系列
*/

#include "opencc_ISO8859.h"

static int cc_iso8859_to_unicode(const void *in, unsigned size, unsigned long *val)
{
    const unsigned char *pin = (const unsigned char *)in;
    
    if (size < 1)
    {
        *val = 0;
        return size;
    }
    
    *val = *pin;
    return 1;
}

static int cc_iso8859_from_unicode(unsigned long val, void *out, unsigned size)
{
    unsigned char *pout = (unsigned char *)out;
    
    if (val < 0x100) /* 单字节 */
    {
        if (pout != NULL && size >= 1)
        {
            *pout++ = val;
        }
        
        return 1;
    }
    
    return -1;
}

static cc_charc_set_t cc_iso8859_set_entry = {
    .charc_type = CC_CHARC_TYPE_ISO9959,
    .min = 1,
    .max = 1,
    .unknown_char = '?',
    .charc_set_to_unicode = cc_iso8859_to_unicode,
    .unicode_to_charc_set = cc_iso8859_from_unicode,
};

cc_charc_set_t *cc_iso8859_get_entry(void)
{
    return &cc_iso8859_set_entry;
}

 

